﻿/*----------------------------------------------------------------
//  <copyright file="ExternalLoginInfoExtensions.cs" company="MicroCloud@151504200868">
//      Copyright © 2020-2024 MicroCloud Corporation, All rights reserved.
//  </copyright>
//  <site>https://gitee.com/chenmm123/microclouds</site>
//  <last-editor>cmm</last-editor>
//  <last-date>2023-09-25 17:17</last-date>
//----------------------------------------------------------------*/

namespace MicroCloud
{
    #region "第三方登录信息扩展"
    /// <summary>
    /// 第三方登录信息扩展
    /// </summary>
    public static class ExternalLoginInfoExtensions
    {
        #region "扩展方法"
        #region "获取第三方登录信息"
        /// <summary>
        /// 获取第三方登录信息
        /// </summary>
        /// <param name="loginInfo"></param>
        /// <returns></returns>
        public static UserLoginInfoEx ToUserLoginInfoEx(this ExternalLoginInfo loginInfo)
        {
            if (loginInfo.Principal.Identity is not ClaimsIdentity identity)
            {
                return null;
            }
            string displayName = identity.GetUserName();
            UserLoginInfoEx info = new(loginInfo.LoginProvider, loginInfo.ProviderKey, displayName)
            {
                AvatarUrl = identity.FindFirst(m => m.Type == ClaimTypeConstants.HeadImgEx)?.Value
            };

            return info;
        }
        #endregion

        #endregion

    }
    #endregion

}
